<!-- 机构跟进人列表 -->
<template>
  <PublicPage bgColor="#F5F5F5">
    <view class="bg-white">
      <view
        v-for="(item,index) in dataList"
        :key="item.userId"
        class="flex mx-3"
        :class="{ borderBottom: index + 1 !== dataList.length }"
        @click="changeSelect(item)">
        <view class="flex items-center flex-shrink-0 pr-3">
          <i
            class="text-xl iconfont"
            :class="selectedBusiness?.userId === item.userId ? 'u-primary' : 'u-info'">
            {{ selectedBusiness?.userId === item.userId ? '&#xe615;' : '&#xe623;' }}
          </i>
        </view>
        <UserCard
          :avatar="item.avatar ? item.avatar : (item.sex === '1' ? GirlProfile : ManProfile)"
          avatarClass="w-10 h-10 rounded-full"
          :userName="item.nickName"
          :com="item.dept.deptName" />
      </view>
    </view>
  </PublicPage>
</template>

<script setup lang="ts">
import { getBusinessUserList } from '@/api/organization'
import { usePageList } from '@/hooks/usePageList'
import UserCard from '@/components/userCard.vue'
import { useUserStore } from "@/stores/user";
import { useExpertStore } from '@/stores/expert'
import { FollowUserInfoTypes } from "@/types/organization";
import ManProfile from '@/static/image/img/manProfile.png'
import GirlProfile from '@/static/image/img/girlProfile.png'


const expertStore = useExpertStore();
const { selectedBusiness } = storeToRefs(expertStore); // 获取已选择业务员
const { userInfo } = useUserStore();

// 获取列表
const {
  getList,
  search,
  list: dataList,
  status: loadStatus
} = usePageList<FollowUserInfoTypes>((params) => getBusinessUserList({...params, channelId: userInfo?.channelId }), { pageSize: 15 })

// 选择机构跟进人
const { setSelectedBusiness } = expertStore
const changeSelect = (item: FollowUserInfoTypes) => {
  setSelectedBusiness(item);
  uni.$u.route({
    type: 'navigateBack',
    delta: 1
  })
}

onLoad(async () => {
  getList()
})
// 下拉刷新
onPullDownRefresh(async () => {
  try {
    await search()
    setTimeout(() => {
      uni.stopPullDownRefresh()
    }, 1000)
  } catch (error) {
    uni.stopPullDownRefresh()
  }
})
// 加载更多
onReachBottom(() => {
  getList()
})
</script>

<style lang="scss" scoped></style>
